package com.adee.netty.mydubbo.server;

import com.adee.netty.mydubbo.HelloService;
import com.adee.netty.mydubbo.HelloServiceImpl;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class MyDubboProviderHandler extends SimpleChannelInboundHandler<String> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println("channelRead0:" + msg);
        if(msg != null ) {
            HelloService s = new HelloServiceImpl();
            String[] arr = msg.split("#");
            String ret = s.hello(arr[arr.length-1]);
            ctx.channel().writeAndFlush(ret);
        } else {
            System.out.println("客户端调用请求格式错误");
            ctx.channel().writeAndFlush("#请求格式错误#");
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
